package com.prs.crm.action.person;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.person.Education;
import com.prs.crm.service.person.EducationService;

public class EducationAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private PaginationSupport pagination;
	private Education education;
	private EducationService educationService;
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public Education getEducation() {
		return education;
	}
	public void setEducation(Education education) {
		this.education = education;
	}
	public EducationService getEducationService() {
		return educationService;
	}
	public void setEducationService(EducationService educationService) {
		this.educationService = educationService;
	}
	
	@Action("listEducation")
	public String listEducation(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(Education.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getEducationService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	
	@Action("editEducation")
	public String editEducation(){
		if(ids!=null){
			this.education=this.getEducationService().get(ids[0]);
		}
		return SUCCESS;
	}
	
	@Action(value="saveEducation",results={
			@Result(name="success",type="redirect",location="listEducation"),
			@Result(name="error",type="chain",location="editEducation")
	})
	public String saveEducation(){
		this.educationService.save(education);
		return SUCCESS;
	}
	
	@Action(value="removeEducation",results={
			@Result(name="success",type="redirect",location="listEducation"),
			@Result(name="error",type="chain",location="listEducation")
	})
	public String removeEducation(){
		if(ids==null){
			this.addActionError("请选择一行进行操作！");
			return ERROR;
		}
		this.getEducationService().batchRemove(ids);
		return SUCCESS;
	}
}
